$(function() {
	// var shopId = getQueryString('shopId');
	// // alert(shopId);
	// var isEdit = shopId ? true : false;
	// var shopInfoUrl = '/shopadmin/getshopbyid?shopId=' + shopId;
	// // var shopInfoUrl = '/o2o/shopadmin/getshopbyid?shopId=' + shopId;
	// var initUrl = '/shopadmin/getshopinitinfo';
	// var addShopUrl = '/shopadmin/registershop';
	// // alert(initUrl);
	// if (isEdit) {
	// 	getInfo();
	// 	editShopUrl = '/shopadmin/modifyshop';
	// }
	// else {
	// 	getCategory();
	// }
	var adduserurl = '/admin/doregister';
	var testloginurl = '/admin/testlogin';
	//提交
	$('#submit').click(function() {
		var bloguser = {};

		bloguser.username = $('#username').val();
		bloguser.password = $('#password').val();
		bloguser.email = $('#email').val();
		bloguser.phone = $('#phone').val();
		bloguser.sex = $('#sex input[name="xingbie"]:checked ').val();
		if (bloguser.sex=='男'){
            bloguser.sex=0;
		} else if(bloguser.sex=='女'){
            bloguser.sex=1;
		}else if(bloguser.sex=='保密'){
            bloguser.sex=2;
		}
		var userimg = $("#imgfile")[0].files[0];

		var formData = new FormData();
        var verifyCodeActual = $('#j_captcha').val();
        if (!verifyCodeActual) {
            $('.input_captcha').click();
            return;
        }
        formData.append("verifyCodeActual", verifyCodeActual);
        formData.append('userimg', userimg);
		formData.append('BlogUserStr', JSON.stringify(bloguser));
		// var verifyCodeActual = $('#j_captcha').val();
		// if (!verifyCodeActual) {
		// 	$.toast('请输入验证码！');
		// 	return;
		// }
		// formData.append("verifyCodeActual", verifyCodeActual);
		$.ajax({
			// url : (isEdit? editShopUrl:addShopUrl),
			url : adduserurl,
			type : 'POST',
			// contentType: "application/x-www-form-urlencoded; charset=utf-8",
			data : formData,
			contentType : false,
			processData : false,
			cache : false,
			success : function(data) {
				if (data.success) {
					$('.addsuccess').click();
                    window.setTimeout("window.location='/community/index'",2000);
					// if (isEdit){
					// 	$('#captcha_img').click();
					// } else{
					// 	window.location.href="/shopadmin/shoplist";
					// }
				} else {
					$('.fail-message').html(data.errMsg);
                    $('.fail').click();
				}
			}
		});
	});

});